import {uuid2} from "@/utils/IdTools";

const prefix = "Process";
export const createEmptyTemplate = (id,name) => {
    if (!id) {
        id = uuid2(32 - prefix.length, 9)
        id = prefix + id;
    }
    return `<?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:activiti="http://activiti.org/bpmn" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:omgdc="http://www.omg.org/spec/DD/20100524/DC" xmlns:omgdi="http://www.omg.org/spec/DD/20100524/DI" typeLanguage="http://www.w3.org/2001/XMLSchema" expressionLanguage="http://www.w3.org/1999/XPath" targetNamespace="http://www.activiti.org/test">
<process id="${id}" name="${name}" isExecutable="true" >
    <startEvent id="startevent1" name="Start"></startEvent>
    <userTask id="usertask1" name="usertask1审批" >
      <documentation>usertask1审批</documentation>
    </userTask>
    <userTask id="usertask2" name="usertask2审批" ></userTask>
    <endEvent id="endevent1" name="End"></endEvent>
    <sequenceFlow id="flow1" name="flow1" sourceRef="startevent1" targetRef="usertask1">
      <documentation>flow1连线</documentation>
     
    </sequenceFlow>
    <sequenceFlow id="flow2" name="flow2" sourceRef="usertask1" targetRef="usertask2">
      <documentation>usertask1审批出线</documentation>
     
    </sequenceFlow>
    <sequenceFlow id="flow3" sourceRef="usertask2" targetRef="endevent1"></sequenceFlow>
  </process>
  <bpmndi:BPMNDiagram id="BPMNDiagram_daling">
    <bpmndi:BPMNPlane bpmnElement="daling" id="BPMNPlane_daling">
      <bpmndi:BPMNShape bpmnElement="startevent1" id="BPMNShape_startevent1">
        <omgdc:Bounds height="35.0" width="35.0" x="230.0" y="10.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="usertask1" id="BPMNShape_usertask1">
        <omgdc:Bounds height="55.0" width="105.0" x="300.0" y="110.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="usertask2" id="BPMNShape_usertask2">
        <omgdc:Bounds height="55.0" width="105.0" x="280.0" y="192.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="endevent1" id="BPMNShape_endevent1">
        <omgdc:Bounds height="35.0" width="35.0" x="230.0" y="340.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNEdge bpmnElement="flow1" id="BPMNEdge_flow1">
        <omgdi:waypoint x="247.0" y="45.0"></omgdi:waypoint>
        <omgdi:waypoint x="352.0" y="110.0"></omgdi:waypoint>
        <bpmndi:BPMNLabel>
          <omgdc:Bounds height="14.0" width="100.0" x="247.0" y="45.0"></omgdc:Bounds>
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="flow2" id="BPMNEdge_flow2">
        <omgdi:waypoint x="352.0" y="165.0"></omgdi:waypoint>
        <omgdi:waypoint x="332.0" y="192.0"></omgdi:waypoint>
        <bpmndi:BPMNLabel>
          <omgdc:Bounds height="14.0" width="100.0" x="352.0" y="165.0"></omgdc:Bounds>
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="flow3" id="BPMNEdge_flow3">
        <omgdi:waypoint x="332.0" y="247.0"></omgdi:waypoint>
        <omgdi:waypoint x="247.0" y="340.0"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
    </bpmndi:BPMNPlane>
  </bpmndi:BPMNDiagram>
</definitions>`

}

/**
 * 是否是事件
 * @param type
 * @returns {*}
 */
export function verifyIsEvent(type) {
    return type.includes('Event')
}

/**
 * 是否是任务
 * @param type
 * @returns {*}
 */
export function verifyIsTask(type) {
    return type.includes('Task')
}

/**
 * 判断是否是无效的值
 * @param param
 * @returns {boolean}
 */
export function isInvalid(param) { //
    return param === null || param === undefined || param === ''
}

/**
 * 判断是否是线
 * @param type
 * @returns {boolean}
 */
export function isSequenceFlow(type) {
    return type === 'bpmn:SequenceFlow'
}

/**
 * 处理人 支持的流程定义类型
 * @type {string[]}
 */
const nodeAssigneeSupportBpmnNodes=[
    "bpmn:UserTask"
]
/**
 * 表单配置 支持的流程定义类型
 * @type {string[]}
 */
const nodeFormSupportBpmnNodes=[
    "bpmn:UserTask"
]

const BpmnUtils={
    createEmptyTemplate,
    verifyIsEvent,
    verifyIsTask,
    isInvalid,
    isSequenceFlow,
    nodeAssigneeSupportBpmnNodes,
    nodeFormSupportBpmnNodes
}



export default BpmnUtils
